<?php

namespace maotool\src\test;

use maotool\core\request\ExportParam;
use maotool\core\response\ExportResult;
use maotool\log\Console;
use maotool\object\ReflectionUtil;
use maotool\office\xls\Xls;
use maotool\office\xlsx\Sheet;
use maotool\office\xlsx\Xlsx;
use PHPUnit\Framework\TestCase;

class XLSXTest extends TestCase
{

    public function testDemo1()
    {
        $xlsx = new Xlsx();
        $xlsx->setName("表格");
        $sheet1 = new Sheet();
        $sheet1->setTitle("用户信息");
        $sheet1->setHeader([
            "name" => "名字",
            "age" => "年龄",
            "sex" => "性别",
            "address" => "地址",
            "phone" => "电话",
            "email" => "邮箱",
            "remark" => "备注",
        ]);
        $sheet1->setList([
            [
                "name" => "maotool",
                "age" => 18,
                "sex" => "男",
                "address" => "北京",
                "phone" => "12345678901",
                "email" => "12345678901@qq.com",
                "remark" => "备注",
            ],
            [
                "name" => "wl4837",
                "age" => 24,
                "sex" => "女",
                "address" => "上海",
                "phone" => "wl4837",
                "email" => "wl4837@163.com",
                "remark" => "测试",
            ],
        ]);
        $sheet1->pagination(function ($pageParam) {
            $pageParam->getPageSize();
            $exportResult = new ExportResult();
            $exportResult->setIsHasNextPage(false);
            $exportResult->setList([
                [
                    "name" => "kingood",
                    "age" => 26,
                    "sex" => "男",
                    "address" => "北京",
                    "phone" => "kingood",
                    "email" => "kingood@163.com",
                    "remark" => "开发",
                ],
            ]);
            return $exportResult;
        }, new ExportParam());
        $sheet2 = new Sheet();
        $sheet2->setTitle("订单信息");
        $sheet2->setHeader([
            "orderId" => "订单编号",
            "goods" => "商品",
            "status" => "状态",
            "money" => "价格",
        ]);
        $sheet2->setList([
            [
                "orderId" => "dsai92i91ksa9d9s0akwqweqwe",
                "goods" => "牙刷",
                "status" => "已完成",
                "money" => 11.3,
            ],
            [
                "orderId" => "213sdadqeqewqeqweqdsaasd",
                "goods" => "牙膏",
                "money" => 18.3,
            ],
        ]);
        $xlsx->setSheets([$sheet1, $sheet2]);
        $xlsx->setPassword("6666");
        $path = $xlsx->writerFile("create-system-temp-file:*.xlsx");
        var_dump($path);
        var_dump(Console::$lines);
        $this->assertTrue(true);
    }

    public function testDemo2()
    {

        $xlsx = new Xlsx();
        $sheet1 = new Sheet();
        $sheet1->setTitle("六级词汇表");
        $sheet1->setHeader([
            "id" => "序号",
            "words" => "单词",
            "annotate" => "释义",
            "mark" => "音标",
            "proficiency" => "熟练度",
        ]);
        $xlsx->setSheets([$sheet1]);
        $xlsx->readerFile("C:/Users/Administrator/Desktop/a.xlsx");
        $this->assertTrue(true);
    }

}